//
//  YLATostStroeView.swift
//  Your Lover AI
//
//  Created by 阿忠 on 2024/7/9.
//

import Foundation
import UIKit

/**
 修改名字的弹窗
 */
class YLATostStroeView: UIView , UITextFieldDelegate {
    private var titleLabel = UILabel()
    var contentLabel = UILabel()
    
    private let cancelButton = UIButton()
    private let confirmButton = UIButton()
    
    var onCancel: (() -> Void)?
    var onConfirm: ((String?) -> Void)?
    
    init(frame: CGRect, title: String, paymentMethod: String, paymentDescription: String) {
        super.init(frame: frame)
        
        setupUI(title: title, paymentMethod: paymentMethod, paymentDescription: paymentDescription)
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    private func setupUI(title: String, paymentMethod: String, paymentDescription: String) {
        // 设置自定义弹窗的样式和布局
        self.backgroundColor = .white
        self.layer.cornerRadius = 20
     
        titleLabel.text = "Kind Tips"
        titleLabel.textColor = .black
        titleLabel.font = UIFont.systemFont(ofSize: 18)
        titleLabel.textAlignment = .center
        titleLabel.numberOfLines = 0
        self.addSubview(titleLabel)
        titleLabel.snp.makeConstraints { make in
            make.top.equalTo(29)
            make.height.equalTo(18)
            make.centerX.equalToSuperview()
        }
        
        contentLabel.text = "Your number of conversations has been exhausted. It is recommended that you upgrade to an annual membership to enjoy unlimited chats."
        contentLabel.textColor = UIColor(hex: "303030")
        contentLabel.font = UIFont.systemFont(ofSize: 15)
        contentLabel.textAlignment = .left
        contentLabel.numberOfLines = 0
        self.addSubview(contentLabel)
        contentLabel.snp.makeConstraints { make in
            make.top.equalTo(titleLabel.snp.bottom).offset(16)
            make.left.equalTo(20)
            make.right.equalTo(-20)
        }
        
       
        
        
        let screenWidth = UIScreen.main.bounds.width
        cancelButton.setTitle("No", for: .normal)
        cancelButton.setTitleColor(.black, for: .normal)
        cancelButton.layer.borderWidth = 0.5
        cancelButton.layer.borderColor = UIColor.black.cgColor
        cancelButton.backgroundColor = .clear
        cancelButton.layer.cornerRadius = 20
        self.addSubview(cancelButton)
        cancelButton.snp.makeConstraints { make in
            make.bottom.equalTo(-20)
            make.left.equalTo(20)
            make.width.equalTo(88)
            make.height.equalTo(46)
        }
        
        confirmButton.setTitle("Subscribe", for: .normal)
        confirmButton.setTitleColor(.white, for: .normal)
        confirmButton.backgroundColor = UIColor(hex: "AB00E4")
        confirmButton.layer.cornerRadius = 20
        self.addSubview(confirmButton)
        confirmButton.snp.makeConstraints { make in
            make.bottom.equalTo(-20)
            make.right.equalTo(-20)
            make.left.equalTo(cancelButton.snp.right).offset(15)
            make.height.equalTo(46)
        }
        
        // 取消按钮点击事件
        cancelButton.addTarget(self, action: #selector(cancelButtonTapped), for: .touchUpInside)
        
        // 确定按钮点击事件
        confirmButton.addTarget(self, action: #selector(confirmButtonTapped), for: .touchUpInside)
    }
    
    // 实现 UITextFieldDelegate 的方法
        func textFieldShouldReturn(_ textField: UITextField) -> Bool {
            textField.resignFirstResponder() // 收起键盘
            return true
        }
    
    @objc private func cancelButtonTapped() {
        onCancel?()
    }
    
    @objc private func confirmButtonTapped() {
        onConfirm?("1")
    }
}
